<template>
  <div>
    <el-row>
      <el-col>
        <div id="main1" style="width: 410px;height:400px; float: left;"></div>
        <div id="main2" style="width: 410px;height:400px; float: left;"></div>
        <div id="main3" style="width: 410px;height:400px; float: left;"></div>
        <div id="main4" style="width: 410px;height:400px; float: left;"></div>
        <!--        <div id="main5" style="width: 350px;height:350px; margin-top: 20px; float: left;"></div>-->
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import * as echarts from 'echarts';

  export default {
    name: "DataCockpitReport",

    mounted() {
      this.initChar1();
      this.initChar2();
      this.initChar3();
      this.initChar4();
      this.initChar5();
    },

    methods: {
      initChar1() {
        var myChart = echarts.init(document.getElementById('main1'));
        // 指定图表的配置项和数据
        var option = {
          title: {
            text: '当月检查统计',
            left: 'center'
          },
          tooltip: {},
          xAxis: {
            data: ['一大队', '二大队', '三大队', '四大队', '五大队', '六大队']
          },
          yAxis: {},
          series: [
            {
              name: '当月检查数量',
              type: 'bar',
              data: [5, 20, 36, 10, 10, 20]
            }
          ]
        };
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
      },
      initChar2() {
        var myChart = echarts.init(document.getElementById('main2'));
        var option = {
          title: {
            text: '施工实时统计',
            left: 'center'
          },
          tooltip: {
            trigger: 'item'
          },
          legend: {
            orient: 'vertical',
            left: 'left'
          },
          series: [
            {
              name: '施工实时统计',
              type: 'pie',
              radius: '50%',
              data: [
                {value: 1, name: '今日进场'},
                {value: 1, name: '今日撤场'},
                {value: 3, name: '占道施工'},
                {value: 5, name: '非占道施工'},
              ],
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
        };

        option && myChart.setOption(option);
      },

      initChar3() {
        var myChart = echarts.init(document.getElementById('main3'));
        // 指定图表的配置项和数据
        var option = {
          title: {
            text: '今日检查情况',
            left: 'center'
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow'
            }
          },
          // legend: {
          //   data: ['总任务数量', '实际执行数量']
          // },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          xAxis: {
            type: 'value',
            splitLine: {
              show: false
            }
          },
          yAxis: {
            type: 'category',
            data: ['一大队', '二大队', '三大队', '四大队', '五大队', '六大队'],
            axisLabel: {
              interval: 0,
              rotate: 0
            }
          },
          series: [
            {
              name: '总任务数量',
              type: 'bar',
              stack: '总量',
              data: [2, 3, 4, 1, 5, 3],
              itemStyle: {
                color: '#4CAF50' // 绿色表示总任务数量
              },
              label: {
                show: true,
                position: 'insideRight',
                formatter: '{c}'
              }
            },
            {
              name: '实际检查数量',
              type: 'bar',
              stack: '总量',
              data: [1, 2, 3, 1, 5, 2],
              itemStyle: {
                color: '#F44336' // 红色表示实际执行数量
              },
              label: {
                show: true,
                position: 'insideRight',
                formatter: function (params) {
                  var total = option.series[0].data[params.dataIndex];
                  var executed = params.value;
                  var percent = ((executed / total) * 100).toFixed(2) + '%';
                  return executed + ' (' + percent + ')';
                }
              }
            }
          ]
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
      },


      initChar4() {
        var myChart = echarts.init(document.getElementById('main4'));
        var option;
        option = {
          title: {
            text: '施工问题统计',
            left: 'center'
          },
          tooltip: {
            trigger: 'item'
          },
          legend: {
            top: '5%',
            left: 'center'
          },
          series: [
            {
              name: '施工问题统计',
              type: 'pie',
              radius: ['40%', '70%'],
              avoidLabelOverlap: false,
              label: {
                show: false,
                position: 'center'
              },
              emphasis: {
                label: {
                  show: true,
                  fontSize: 40,
                  fontWeight: 'bold'
                }
              },
              labelLine: {
                show: false
              },
              data: [
                {value: 2, name: '待整改'},
                {value: 3, name: '未整改'},
                {value: 3, name: '整改通过'}
              ]
            }
          ]
        };
        option && myChart.setOption(option);
      },

      initChar5() {
        var myChart = echarts.init(document.getElementById('main5'));
        // 指定图表的配置项和数据
        var option = {
          title: {
            text: 'ECharts 入门示例'
          },
          tooltip: {},
          legend: {
            data: ['销量']
          },
          xAxis: {
            data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
          },
          yAxis: {},
          series: [
            {
              name: '销量',
              type: 'bar',
              data: [5, 20, 36, 10, 10, 20]
            }
          ]
        };
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
      }
    }
  }

</script>
